package com.chii.color.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.chii.color.po.Config;
import com.chii.color.po.ResponeInfo;
import com.chii.color.service.ConfigSevice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Api(value = "设置controller", tags = {"设置"})
@RestController
@RequestMapping(value = "/config")
public class ConfigController {
    @Autowired
    private ConfigSevice configSevice;

    @ApiOperation(value = "获取设置")
    @SentinelResource(value="base-config")
    @RequestMapping(value = "/base", method = RequestMethod.GET)
    public ResponeInfo config() throws IOException {
        ResponeInfo responeInfo = new ResponeInfo();
        Config config = configSevice.getBaseConfig();
        responeInfo.setData(config);
        return responeInfo;
    }

    @ApiOperation(value = "修改设置")
    @RequestMapping(value = "/base", method = RequestMethod.PATCH)
    public ResponeInfo setConfig() throws IOException {
        ResponeInfo responeInfo = new ResponeInfo();
        Config config = configSevice.getBaseConfig();
        responeInfo.setData(config);
        return responeInfo;
    }
}
